import java.nio.IntBuffer;

/**
 * @Author zhang lei
 * @Date 2021-11-30 18:50
 */
public class IntBufferTest {
    public static void main(String[] args) {
        IntBuffer intBuffer = IntBuffer.allocate(20);

        printBuffer(intBuffer);

        for (int i = 0; i < 5; i++) {
            intBuffer.put(i);
        }

        printBuffer(intBuffer);

        intBuffer.flip();

        printBuffer(intBuffer);

        for (int i = 0; i < 2; i++) {
            intBuffer.get();
        }
//        intBuffer.clear();
//        intBuffer.compact();
        printBuffer(intBuffer);
    }

    private static void printBuffer(IntBuffer intBuffer) {
        System.out.println("position:"+intBuffer.position());
        System.out.println("limit : "+ intBuffer.limit() );
        System.out.println("capacity : "+ intBuffer.capacity() );
    }
}
